package org.gruposp2p.proyectokarma.gwt.client.ui;

import org.gruposp2p.proyectokarma.gwt.client.MainEntryPoint;
import org.gruposp2p.proyectokarma.gwt.client.cometd.CometdPanel;
import org.gruposp2p.proyectokarma.gwt.client.cometd.SearchMessagesPanel;
import org.gruposp2p.proyectokarma.gwt.client.ui.admin.AdminPanel;
import org.gruposp2p.proyectokarma.gwt.client.ui.comment.SearchCommentPanel;
import org.gruposp2p.proyectokarma.gwt.client.ui.document.EditorPanel;
import org.gruposp2p.proyectokarma.gwt.client.ui.document.SearchDocumentPanel;
import org.gruposp2p.proyectokarma.gwt.client.ui.tag.TagPanel;
import org.gruposp2p.proyectokarma.gwt.client.ui.user.SearchUserPanel;
import org.gruposp2p.proyectokarma.gwt.client.ui.vote.SearchVotePanel;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.allen_sauer.gwt.log.client.Log;
/**
 * @author jj
 */
public class CentralPanel extends Composite {

    private static CentralPanelUiBinder uiBinder = GWT.create(CentralPanelUiBinder.class);
    interface CentralPanelUiBinder extends UiBinder<Widget, CentralPanel> { }

    @UiField VerticalPanel selectedPanel;
    @UiField StartPanel startPanel;
    @UiField SearchUserPanel searchUserPanel;
    @UiField SearchDocumentPanel searchDocumentPanel;
    @UiField SearchCommentPanel searchCommentPanel;
    @UiField SearchVotePanel searchVotePanel;
    @UiField SearchMessagesPanel searchMessagesPanel;
    @UiField CometdPanel cometdPanel;
    @UiField  AdminPanel adminPanel;
    @UiField TagPanel tagPanel;
    @UiField EditorPanel editorPanel;
    

    public CentralPanel() {
        initWidget(uiBinder.createAndBindUi(this));
    }

    public void setPanel (String historyToken) {
    	if (selectedPanel != null) selectedPanel.clear();
    	selectedPanel.setHeight("400px");
        if (historyToken.equals(TopPanel.HISTORY_START)){
        	selectedPanel.add(startPanel);
        } else if (historyToken.equals(TopPanel.HISTORY_SEND_MESSAGES)){
        	selectedPanel.add(cometdPanel);
        } else if (historyToken.equals(TopPanel.HISTORY_SEARCH_MESSAGES)){
        	selectedPanel.add(searchMessagesPanel);
        } else if (historyToken.equals(TopPanel.HISTORY_LOGIN)){
        	selectedPanel.add(cometdPanel);
        } else if (historyToken.equals(TopPanel.HISTORY_SEARCH_DOCUMENTS)){
        	selectedPanel.add(searchDocumentPanel);
        } else if (historyToken.equals(TopPanel.HISTORY_SEARCH_COMMENTS)){
        	selectedPanel.add(searchCommentPanel);
        } else if (historyToken.equals(TopPanel.HISTORY_SEARCH_USER)){
        	selectedPanel.add(searchUserPanel);
        } else if (historyToken.equals(TopPanel.HISTORY_SEARCH_VOTES)){
        	selectedPanel.add(searchVotePanel);
        } else if (historyToken.equals(TopPanel.HISTORY_ADMIN)){
        	selectedPanel.add(adminPanel);
        } else if (historyToken.equals(TopPanel.HISTORY_TAG)){
        	if (MainEntryPoint.INSTANCE.sessionData.getSelectedTag() == null) {
            	History.newItem(TopPanel.HISTORY_START);
            	History.fireCurrentHistoryState(); 
        	}
        	selectedPanel.add(tagPanel);
        } else if (historyToken.equals(TopPanel.HISTORY_CREATE_DOCUMENTS)){
        	selectedPanel.add(editorPanel);
        	editorPanel.show();
        }
    }

}